package com.helloworld.demo.jmm;

import sun.misc.Contended;

public class FalseShareingTest {
    public static void main(String[] args) throws InterruptedException {
        testPoint(new Point());
    }

    public static void testPoint(Point point) throws InterruptedException {
        long start = System.currentTimeMillis();

        Thread threadA = new Thread(() -> {
            for (int i = 0; i < 100000000; i++) {
                point.x++;
            }
        });

        Thread threadB = new Thread(() -> {
            for (int i = 0; i < 100000000; i++) {
                point.y++;
            }
        });

        threadA.start();
        threadB.start();
        threadA.join();
        threadB.join();

        long end = System.currentTimeMillis();
        System.out.println(point.x);
        System.out.println(point.y);
        System.out.println(end-start);
    }

}

class Point{
    //@Contended
    long x;

//    long a,b,c,d,e,f,g;
//    volatile long x;

    long y;
//    volatile long y;
}
